const {
    app,
    BrowserWindow,
    ipcMain
} = require("electron");

//const reloader = require("electron-reloader");
//const {globalShortcut} = require("@electron/remote");
//reloader(module);

const path = require("path");
const fs = require("fs");


// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win;

async function createWindow() {
    // Create the browser window.
    win = new BrowserWindow({
        frame: false,
        width: 1280,
        height: 920,
        webPreferences: {
            nodeIntegration: false, // is default value after Electron v5
            contextIsolation: true, // protect against prototype pollution
            enableRemoteModule: false, // turn off remote
            preload: path.join(__dirname, "preload.js") // use a preload script
        }
    });

    //require('@electron/remote/main').initialize();
    //require('@electron/remote/main').enable(mainWindows.webContents);

    // Load app
    //win.loadFile(path.join(__dirname, "http://localhost:8080/"));
    win.loadURL("http://localhost:8080/");

    // rest of code..
    let id3 = require("../nodeID3/index");

    ipcMain.on("getImageCover", (event, args) => {
        console.log("我接收到了请求")
        /*console.log(event,args)
        let imageInfo = id3.getImageInfo();
        console.log(imageInfo)
        win.webContents.send("imageCover", imageInfo);
        event.sender.send("imageCover", imageInfo);*/
    });
}

app.on("ready", createWindow);

